<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>">

<title>交费处</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		//初始化数据表格
		$('#j_i_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/chufangAction!findAllChuFang.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'creatDate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			striped : true,
			rownumbers : true,
			singleSelect : true,
			columns : [ [ {
				field : 'todayId',
				title : '挂号单单号',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'patientId',
				title : '挂号单单号',
				width : 150,
				align : 'center',
				hidden : true,
				sortable : true
			}, {
				field : 'pname',
				title : '病人姓名',
				align : 'center',
				width : 150,
				sortable : true
			}, {
				field : 'totalPrice',
				title : '价格',
				align : 'center',
				width : 150,
				sortable : true
			}, {
				field : 'creatDate',
				title : '创建时间',
				align : 'center',
				width : 150,
				sortable : true
			}, {
				field : 'caozuo',
				title : '操作',
				align : 'center',
				width : 150,
				sortable : true,
				formatter : function(value, row, index) {
					var str = '<a href="javascript:void(0)" onclick="append()">缴费</a>';
					str += '&nbsp;&nbsp;<a href="javascript:void(0)" onclick="over(\'' + row.patientId + ' \')">完成</a>';
					return str;
				}
			}

			] ],
			toolbar : [ {
				text : '缴费',
				iconCls : 'icon-add',
				handler : function() {
					append();
				}
			}, '-' ]

		});
		//初始化模式化窗口
		$('#dialog').dialog({
			closed : true,
			modal : true,
			width : 500,
			hight : 500,
			title : '缴费',
			buttons : [ {
				text : '提交',
				iconCls : 'icon-add',
				handler : function() {
					$('#j_i_form').form('submit', {
						url : '${pageContext.request.contextPath}/patientAction!updatePatient.action',
						success : function(d) {
							var obj = jQuery.parseJSON(d);
							if (obj.success) {
								$('#dialog').dialog('close');
								$('#j_i_datagrid').datagrid('load');
							}
							$.messager.show({
								title : '提示',
								msg : obj.msg
							});
						}
					});
				}
			}, {
				text : '取消',
				iconCls : 'icon-remove',
				handler : function() {
					$('#dialog').dialog('close');
				}
			} ]
		});
	});
	//完成缴费
	function over(id) {
		$.messager.confirm('提示', '你确定完成缴费吗?', function(r) {
			if (r) {
				$.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/patientAction!updatePatient.action",
					data : "patientId=" + id,
					dataType : 'json',
					success : function(msg) {
						if (msg.success) {
							$('#doctor_index_datagrid').datagrid('reload');
						}
						$.messager.show({
							title : '提示',
							msg : msg.msg,
						});
					}
				});
			}
		});

	}
	//找钱
	function zhao() {
		var money = parseFloat($('#j_i_form input[name=jiaofei]').val()) - parseFloat($('#j_i_form input[name=totalPrice]').val());
		$('#zl').html(money);
	}
	//弹出缴费窗口
	function append() {
		var get = $('#j_i_datagrid').datagrid('getSelected');
		if (get == null) {
			$.messager.alert('提示', '请选择一个选项', 'error');
		} else {
			$('#dialog').dialog('open');
			$('#j_i_form').form('load', get);

		}
	}
</script>
</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center'">
		<table id="j_i_datagrid">

		</table>
		<div id="dialog">
			<form id="j_i_form" method="post">
				<table cellpadding="5">
					<tr>
						<td>挂号单:</td>
						<td><input readonly="readonly" type="text" name="todayId" data-options="required:true"></td>
					</tr>
					<tr>
						<td>姓名:</td>
						<td><input  readonly="readonly" type="text" name="pname" data-options="required:true"></td>
					</tr>
					<tr>
						<td>时间:</td>
						<td><input readonly="readonly" type="text" name="creatDate" data-options="required:true,validType:'email'"></td>
					</tr>
					<tr>
						<td>费用:<input type="hidden"  name="patientId" /></td>
						<td><input  readonly="readonly" type="text" name="totalPrice" data-options="required:true"></td>
					</tr>
					<tr>
						<td>实际交费:</td>
						<td><input class="easyui-validatebox" type="text" name="jiaofei"><input class="easyui-linkbutton" type="button" onclick="zhao()" value="找钱" /></td>
					</tr>
					<tr>
						<td>找零:</td>
						<td><span id="zl"></span></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>
